/**
 * 
 */
package com.imonsoft.common.util;

import org.apache.commons.lang.ArrayUtils;

/**
 * 
 * @author LiQianHui
 * @date 2013-04-17
 * @version 2013
 */
public abstract class ArrayUtil  extends ArrayUtils {

	/**
	 * 
	 * @param obj
	 *            [obj1,obj2,...]
	 * @param obj2
	 *            [o1,o2,...] 或 o1
	 * @return obj3 [obj1,obj2,...,o1,o2,...] 或 [obj1,obj2,...,o1]
	 */
	public static Object[] concat(Object obj, Object... obj2) {
		Object[] obj3 = null;
		if (!(obj instanceof Object[])) {
			obj = new Object[] { obj };
		}
		int len = ((Object[]) obj).length;
		if (obj2 instanceof Object[]) {
			obj3 = new Object[len + obj2.length];
			System.arraycopy(obj, 0, obj3, 0, len);
			System.arraycopy(obj2, 0, obj3, len, obj2.length);
		} else {
			obj3 = new Object[len + 1];
			System.arraycopy(obj, 0, obj3, 0, len);
			obj3[len] = obj2;
		}
		return obj3;
	}

	public static Object[] subarray(Object[] array, int startIndex) {
		Object[] toArray = new Object[array.length - startIndex];
		System.arraycopy(array, startIndex, toArray, 0, array.length
				- startIndex);
		return toArray;
	}

	/**
	 * 将Object数组(内部存储的必须是String)转化为String数组
	 * @param array
	 * @return
	 */
	public static String[] toStringArray(Object[] array) {
		String[] toArray = new String[array.length];
		System.arraycopy(array, 0, toArray, 0, array.length);
		return toArray;
	}
	
	public static void main(String[] args) {
		Object[] obj1 = { 1, "String" };
		Object[] obj2 = { 2, "OherStr" };
		Object obj = "3Str";
		System.out.println(concat(obj1, obj2)[3]);
		System.out.println(concat(obj1, obj)[2]);
		System.out.println(concat(obj, obj1)[0]);
		Object[] arr = {"1","2"};
		System.out.println(toStringArray(arr)[0].getClass());
	}
}
